package com.ljc.cjgl.controller.bbs;

import com.ljc.cjgl.entitiy.bbs.Article;
import com.ljc.cjgl.security.SysUser;
import com.ljc.cjgl.security.SysUserRepository;
import com.ljc.cjgl.service.bbs.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author: JavaJun
 * Date: 2019-05-06 15:47
 */
@Controller
@RequestMapping(value = "/bbs/user")
public class UserController {

    // 这里没有严格遵守 MVC 设计模式，应该装载的是服务层，而不是repository
    @Autowired
    private SysUserRepository sysUserRepository;

    @Autowired
    private ArticleService articleService;


    @GetMapping(value = "/{username}")
    public String getUser(@PathVariable String username, ModelMap map) {
        SysUser user = sysUserRepository.findByUsername(username);
        List<Article> articleList = articleService.findBySysUserUsername(username);
        map.put("user", user);
        map.put("articleList", articleList);
        return "bbs/user/personal";
    }
}
